<template>
  <echarts :data-array="randarEchart" classify="randar"/>
</template>

<script>
import Vue from 'vue'

export default {
  components: {
    echarts: Vue.extend(require('./echarts/index').default)
  },
  props: {
    classify: { // 应用那个类型的图标
      type: String,
      default: ''
    },
    testData: { // 柱状图渲染数据,数据的每一项都是Number
      type: Array,
      default() {
        return []
      }
    },
    index: {
      type: Array,
      default() {
        return []
      }
    },
    lat: { // 文案单位
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      // type: this.classify,
      type: 'barHeng,',
      tableData: this.testData,
      latChoose: this.lat,
      indexChoose: this.index,
      dataArr: [],
      randarEchart: [[{
        value: [100, 8, 0.40, -80, 2000],
        name: 'web',
        symbol: 'star5',
        symbolSize: 4, // 可计算特性参数，空数据拖拽提示图形大小
        itemStyle: {
          normal: {
            lineStyle: {
              type: 'dashed'
            }
          }
        }
      },
      {
        value: [10, 3, 0.20, -100, 1000],
        name: '图二',
        itemStyle: {
          normal: {
            areaStyle: {
              type: 'default'
            }
          }
        }
      },
      {
        value: [20, 3, 0.3, -13.5, 3000],
        name: '图三',
        symbol: 'none', // 拐点图形类型，非标准参数
        itemStyle: {
          normal: {
            lineStyle: {
              type: 'dotted'
            }
          }
        }
      }], [{
        value: [120, 118, 130, 100, 99, 70],
        name: '张三',
        symbol: 'none', // 拐点图形类型，非标准参数
        itemStyle: {
          normal: {
            lineStyle: {
              type: 'dotted'
            }
          }
        }
      }, {
        value: [120, 118, 130, 100, 99, 70],
        name: '李四',
        symbol: 'none', // 拐点图形类型，非标准参数
        itemStyle: {
          normal: {
            lineStyle: {
              type: 'dotted'
            }
          }
        }
      }, {
        value: [120, 118, 130, 100, 99, 70],
        name: '王五',
        symbol: 'none', // 拐点图形类型，非标准参数
        itemStyle: {
          normal: {
            lineStyle: {
              type: 'dotted'
            }
          }
        }
      }]]
    }
  },
  created() {
    console.log('create')
    console.log('letchoose', this.index)
    console.log(('indexchoose', this.indexChoose))
    this.randarEchart.map((item) => {
      console.log('randerdata', item)
    })
    if (this.latChoose.some(e => e === 0)) {
      this.tableData.map((item, index) => {
        if (this.latChoose.some(e => e === 0)) {
          if (this.latChoose.some(e => e === 1)) {
            item.fault.map((items, indexs) => {
              if (this.indexChoose.length === 0) {
                this.dataArr.push({
                  value: items.index[0].data,
                  name: item.province + items.faultName
                })
              } else {
                this.indexChoose.map((indexItem) => {
                  this.dataArr.push({
                    value: items.index[indexItem].data,
                    name: item.province + items.faultName + items.index[indexItem].name
                  })
                })
              }
            })
          } else {
            if (this.indexChoose.length === 0) {
              this.dataArr.push({
                value: item.fault[0].index[0].data,
                name: item.province + item.fault[0].index[0].name
              })
            } else {
              this.indexChoose.map((indexItem) => {
                this.dataArr.push({
                  value: item.fault[0].index[indexItem].data,
                  name: item.province + item.fault[0].index[indexItem].name
                })
              })
            }
          }
        }
      })
      return
    }

    if (this.latChoose.some(e => e === 1)) {
      this.tableData[0].fault.map((item, index) => {
        if (this.indexChoose.length === 0) {
          this.dataArr.push({
            value: this.tableData[0].fault[index].index[0].data + this.tableData[1].fault[index].index[0].data + this.tableData[2].fault[index].index[0].data,
            name: item.faultName + item.index[0].name
          })
        } else {
          this.indexChoose.map((indexItem, ind) => {
            this.dataArr.push({
              value: this.tableData[0].fault[index].index[indexItem].data + this.tableData[1].fault[index].index[indexItem].data + this.tableData[2].fault[index].index[indexItem].data,
              name: item.faultName + item.index[indexItem].name
            })
          })
        }
      })
    }
    console.log('dataArr', this.dataArr)
    this.dataArr.map(item => {
      this.randarEchart[0].value.push(item.value)
      this.randarEchart[0].name.push(item.name)
    })
  }

}
</script>
